
let {list}=require('./mock')
module.exports=app=>{
    app.get('/api/list',(req,res)=>{
        res.send({
            list
        })
    })
    app.get('/api/shan',(req,res)=>{
        const {id}=req.query
        list=list.filter(v=>v.id!==id)
        res.send({
            list
        })
    })
    app.get('/api/item',(req,res)=>{
        const {id}=req.query
        list.forEach(v=>{
            if(v.id===id){
                res.send({
                    item:v
                })
            }
        })
    })
    app.get('/api/isFinite',(req,res)=>{
        const {id}=req.query
        list=list.map(v=>{
            if(v.id===id){
                return {...v,isFinite:!v.isFinite}
            }
            return v
        })
    })
    app.get('/api/add',(req,res)=>{
        const {title,url,name,isFinite,id,children=[]}=req.query
        list.push({title,url,name,isFinite,id,children})
        res.send({
            list
        })
    })
}